//
//  ClassListTableHeaderView.m
//  huashiedu
//
//  Created by oceans on 2018/8/27.
//  Copyright © 2018年 hema. All rights reserved.
//

#import "ClassListTableHeaderView.h"
#import "LocationModel.h"

@implementation ClassListTableHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    self.backgroundColor = [UIColor whiteColor];
    
    NSString *string = @"全部区域";
    if ([LocationModel shared].areaName.length > 0) {
        string = [LocationModel shared].areaName;
    }
    
    NSArray *titles = @[string, @"智能排序", @"全部时间"];
    for (NSInteger i = 0; i < 3; i ++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = i;
        [button addTarget:self action:@selector(buttonsPressed:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(ScreenWidth / 3.0 * i, 0, ScreenWidth / 3.0, 35);
        button.titleLabel.font = [UIFont systemFontOfSize:13.0];
        [button setTitleColor:COLOR(128, 128, 128, 1) forState:UIControlStateNormal];
        [button setTitle:titles[i] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"gray_triangle"] forState:UIControlStateNormal];
        button.backgroundColor = [UIColor whiteColor];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -button.imageView.bounds.size.width, 0, button.imageView.bounds.size.width)];
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, button.titleLabel.bounds.size.width + 5, 0, -button.titleLabel.bounds.size.width)];
        if (i > 0) {
            
            CALayer *line = [[CALayer alloc] init];
            line.backgroundColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0].CGColor;
            line.frame = CGRectMake(ScreenWidth / 3.0 * i, 10, 0.5, 15);
            [self.layer addSublayer:line];
        }
        [self addSubview:button];
    }
    
    CALayer *line = [[CALayer alloc] init];
    line.frame = CGRectMake(0, 35.5, ScreenWidth, 0.5);
    line.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1.0].CGColor;
    [self.layer addSublayer:line];
}

- (void)buttonsPressed:(UIButton *)sender {
    
    [_delegate tableHeaderViewButton:sender];
}



@end
